package cn.xiongxf.controller;

import cn.xiongxf.domain.Movie;
import cn.xiongxf.domain.User;
import cn.xiongxf.domain.UserMovie;
import cn.xiongxf.service.UserService;
import cn.xiongxf.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 查询所有
     * @return
     */
    @GetMapping("/list")
    public List<Movie> findAll(){
        try {
            return userService.findAll();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 买票
     * @param userMovie
     * @return
     */
    @PostMapping("/purchase")
    public AjaxResult purchase(@RequestBody UserMovie userMovie){
        return userService.purchase(userMovie);
    }

    @PostMapping("/add")
    public AjaxResult add(@RequestBody User user){
        try {
            userService.add(user);
            return new AjaxResult(true,"添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"添加失败");
        }
    }

    @PostMapping("/watch")
    public AjaxResult watch(@RequestBody UserMovie userMovie){
        return userService.watch(userMovie);
    }





}
